package gang.org.springframework.framework.util;

/**
 * @author gang.chen
 * @Date 2021/8/26 8:13
 */
public class GangObjectUtils {

    private static final String empty_string = "";

    public static Object unwrapOptional(Object obj){

        //TODO
        return obj;
    }

    public static boolean nullSafeEquals(Object o1, Object o2){
        if (o1 == o2) {
            return true;
        }
        if (o1 == null || o2 == null) {
            return false;
        }
        if (o1.equals(o2)) {
            return true;
        }
        //TODO if (o1.getClass().isArray() && o2.getClass().isArray())
        return false;
    }

    public static boolean isEmpty(Object[] array){
        return array == null || array.length == 0;
    }

    public static String identityToString(Object obj){
        if (obj == null) {
            return empty_string;
        }
        return obj.getClass().getName()+"@" + getIdentityHexString(obj);
    }


    public static String getIdentityHexString(Object obj){
        return  Integer.toHexString(System.identityHashCode(obj));
    }
}
